package ai.plantdata.Behavior.mode.ChainofResponsibilityPattern.test;

import ai.plantdata.Behavior.mode.ChainofResponsibilityPattern.adstracts.AbstractLogger;
import ai.plantdata.Behavior.mode.ChainofResponsibilityPattern.logger.ConsoleLogger;
import ai.plantdata.Behavior.mode.ChainofResponsibilityPattern.logger.ErrorLogger;
import ai.plantdata.Behavior.mode.ChainofResponsibilityPattern.logger.FileLogger;

/**
 * @Author: WangHui
 * @Date: 2020/12/21 17:54
 * @Description:
 */
public class ChainPatternDemo {
    private static AbstractLogger getChainOfLoggers(){
        AbstractLogger errorLogger = new ErrorLogger(AbstractLogger.ERROR);
        AbstractLogger fileLogger = new FileLogger(AbstractLogger.DEBUG);
        AbstractLogger consoleLogger = new ConsoleLogger(AbstractLogger.INFO);

        errorLogger.setNextLogger(fileLogger);
        fileLogger.setNextLogger(consoleLogger);

        return errorLogger;
    }

    public static void main(String[] args) {
        AbstractLogger loggerChain = getChainOfLoggers();
        loggerChain.logMessage(AbstractLogger.INFO,"This is an information.");
        loggerChain.logMessage(AbstractLogger.DEBUG,"This is a debug level information. ");
        loggerChain.logMessage(AbstractLogger.ERROR,"This is an error information.");
    }
}
